package com.digigames;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ItemObjectAdapter extends ArrayAdapter<ItemObject> {

	private ArrayList<ItemObject> items;

	public ItemObjectAdapter(Context context, int textViewResourceId,
			ArrayList<ItemObject> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);

			v = vi.inflate(R.layout.item_row, null);
		}
		ItemObject o = items.get(position);

		if (o != null) {
			TextView lblItem = (TextView) v.findViewById(R.id.textViewItem);
			TextView lblDetail = (TextView) v.findViewById(R.id.textViewDetail);

			if (lblItem != null) {
				String strItem = o.getItem();
				if (strItem.length() > 100) {
					lblItem.setText(o.getItem().substring(0, 99) + "....");
				} else {
					lblItem.setText(o.getItem());
				}

			}
			if (lblDetail != null) {
				String strDetail = o.getDetail();
				
				if (strDetail.length() > 100) {
					lblDetail.setText(strDetail.substring(0, 99) + "....");
				} else {
					lblDetail.setText(strDetail);
				}
				
			}
		}
		return v;
	}
}
